import axios from 'axios';
import { Indicator, Toast} from 'mint-ui';
import store from '../store';
// import {Server} from 'tis';

//自定义配置创建axios的新实例
const service=axios.create({
   baseURL:'http://t.yushu.im/v2/movie',
   timeout:50000
}) 
//请求加载
service.interceptors.request.use(
   config=>{
     Indicator.open();
     if(store.state.token){
        config.headers.token=store.state.token;
        config.headers.userId=store.state.userInfo.id;
     }
     return config;
   },
   error=>{
     return Promise.reject(error);
   }
)
//请求完成
service.interceptors.response.use(
    response=>{
      if(!store.state.multiple){
         Indicator.close();
         return response;
       }else
       if(response.data.status.statusCode===0){
         Indicator.close();
         return response;
       }else{
          Toast(response.data.status.statusReason)
          return Promise.reject(response.data.status.statusReason)
       }
        
    },
    error=>{
      Indicator.close();
      return Promise.reject(error)
    }
)


export default service; 